package com.lbi.framework.collection {
	import flash.events.IEventDispatcher;
	
	import asunit.framework.TestCase;		
	public class CollectionTest extends TestCase {
		private var collection : Collection;
	
		private var first : DummySelectable;
		
		override protected function setUp() :void{
			collection = new Collection();
			var items : Array = ["one","two","three","four"];
			for (var i : Number = 0; i < items.length; i++) {
				var id:String = items[i];
				collection.AS3::push(new DummySelectable(id));			
			}
			assertNull("nothing should be selected initially - found " + collection.current(),
						collection.current());
			first = DummySelectable(collection.first());
			assertTrue(first instanceof DummySelectable);
			assertEquals("one",first.id);
			collection.select(first);
		}
		override protected function tearDown() :void{
			collection = null;	
		}
		private function testCollectionSelections() :void{
			
			
			assertEquals(0,collection.getCurrentIndex());
			var current : DummySelectable = DummySelectable(collection.current());
			assertTrue("current() should return a DummySelectable - we got " + current,
						current instanceof DummySelectable);
			assertEquals("expected the first item to be selected. but it wasn't",
						"one",current.id);
		}
//		private function testCollectionEvents() :void{
//			
//			checkEvent(collection,Collection.CHANGED, collection.next, "collection should dispatch changed when next() is called");
//			checkEvent(collection,Collection.INCREASED, collection.next, "collection should dispatch changed when next() is called");
//			
//		}
//		private function testItemEvents() :void{
//			var selected_worked : Boolean = false;
//			var deselected_worked : Boolean = false;
//			first.addEventListener(Selectable.SELECTED,function(){
//				selected_worked = true;	
//			});
//			first.addEventListener(Selectable.DESELECTED,function(){
//				deselected_worked = true;
//			});
//			collection.next();
//			assertTrue(deselected_worked);
//			collection.select(first);
//			assertTrue(selected_worked);
//		}
	
		private function checkEvent(object : IEventDispatcher, event : String, call : Function,message:String) : void {
			var test : Boolean = false;
			object.addEventListener(event,function():void{
				test = true;
			});
			call();
			assertTrue(message,test);
		}
	}
}